package com.culturalCenter.dataCenter.controller.web;

import com.culturalCenter.dataCenter.Utils.ApiResult;
import com.culturalCenter.dataCenter.Utils.ResultCode;
import com.culturalCenter.dataCenter.customEntity.responseParam.user.*;
import com.culturalCenter.dataCenter.customEntity.user.CustomActivityStatistics;
import com.culturalCenter.dataCenter.customEntity.user.CustomListUser;
import com.culturalCenter.dataCenter.customEntity.user.CustomLocationStatistics;
import com.culturalCenter.dataCenter.customEntity.user.CustomPointStatistics;
import com.culturalCenter.dataCenter.entity.user.UserActivity;
import com.culturalCenter.dataCenter.entity.user.UserActivityLog;
import com.culturalCenter.dataCenter.entity.user.UserFootrpintCount;
import com.culturalCenter.dataCenter.globalconfig.Interface.ApiVersion;
import com.culturalCenter.dataCenter.globalconfig.Interface.CustomVersion;
import com.culturalCenter.dataCenter.service.user.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import static com.culturalCenter.dataCenter.Utils.ApiResult.instance;

/**** 用户
 * @Author www.rookie.com
 * @Date 2020/8/25 14:27
 *****/
@RestController
@RequestMapping("/{version}/user")
@Api(tags = "用户模块")
@ApiVersion(CustomVersion.VERSION_1)
@Slf4j
public class UserController {

    @Resource
    private UserService userService;
    @Resource
    private UserPointService userPointService;
    @Resource
    private UserLocationService userLocationService;
    @Resource
    private UserActivityService userActivityService;
    @Resource
    private UserFootprintService userFootprintService;
    @Resource
    private UserActivityLogService userActivityLogService;
    @Resource
    private UserActivityCountService userActivityCountService;
    @Resource
    private UserFootrpintCountService userFootrpintCountService;

    /**
     * 主页
     */
    @GetMapping("menu")
    @ApiOperation(value = "用户主页", notes = "用户主页")
    public ApiResult<UserMenuResponse> menu() {
        UserMenuResponse userMenuResponse = userService.getMenuData();
        return instance(ResultCode.SUCCESS, userMenuResponse);
    }

    /**
     * 列表
     */
    @GetMapping("userList")
    @ApiOperation(value = "用户列表", notes = "用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页面尺寸", paramType = "query", dataType = "int")
    })
    public ApiResult<UserListResponse> getUserList(@RequestParam(required = false) String branchId,@RequestParam(required = false) String username, @RequestParam(required = false, defaultValue = "1") int pageNum, @RequestParam(required = false, defaultValue = "15") int pageSize) {
        UserListResponse userListResponse = userService.findUserList(branchId,username, pageNum, pageSize);
        return instance(ResultCode.SUCCESS, userListResponse);
    }

    /**
     * 基本信息
     */
    @GetMapping("userInfo")
    @ApiOperation(value = "用户基本信息", notes = "用户基本信息")
    @ApiImplicitParams(@ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String"))
    public ApiResult<UserInfoResponse> getUserInfo(@RequestParam String userId) {
        UserInfoResponse userInfoResponse = userService.findUserInfo(userId);
        return instance(ResultCode.SUCCESS, userInfoResponse);
    }

    /**
     * 浏览记录_列表
     */
    @GetMapping("footprint/list")
    @ApiOperation(value = "用户浏览记录_列表", notes = "用户浏览记录_列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页面尺寸", paramType = "query", dataType = "int")
    })
    public ApiResult<PageInfo<UserFootprintListResponse>> getFootprintList(@RequestParam String userId, @RequestParam(required = false, defaultValue = "1") int pageNum, @RequestParam(required = false, defaultValue = "5") int pageSize) {
        PageInfo<UserFootprintListResponse> userFootprintListResponsePageInfo = userFootprintService.findFootprintList(userId, pageNum, pageSize);
        return instance(ResultCode.SUCCESS, userFootprintListResponsePageInfo);
    }

    /**
     * 浏览记录_统计
     */
    @GetMapping("footprint/statistics")
    @ApiOperation(value = "用户浏览记录_统计", notes = "用户浏览记录_统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String")
    })
    public ApiResult<UserFootrpintCount> getFootprintStatistics(@RequestParam String userId) {
        UserFootrpintCount userFootrpintCount = userFootrpintCountService.findByUserId(userId);
        return instance(ResultCode.SUCCESS, userFootrpintCount);
    }

    /**
     * 活动记录_列表
     */
    @GetMapping("activity/list")
    @ApiOperation(value = "用户活动记录_列表", notes = "用户活动记录_列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页面尺寸", paramType = "query", dataType = "int")
    })
    public ApiResult<PageInfo<UserActivity>> getActivityList(@RequestParam String userId, @RequestParam(required = false, defaultValue = "1") int pageNum, @RequestParam(required = false, defaultValue = "5") int pageSize) {
        PageInfo<UserActivity> pageInfo = userActivityService.findActivityList(userId, pageNum, pageSize);
        return instance(ResultCode.SUCCESS, pageInfo);
    }

    /**
     * 活动记录_统计
     */
    @GetMapping("activity/statistics")
    @ApiOperation(value = "用户活动记录_统计", notes = "用户活动记录_统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String")
    })
    public ApiResult<CustomActivityStatistics> getActivityStatistics(@RequestParam String userId) {
        CustomActivityStatistics customActivityStatistics = userActivityCountService.findByUserIdAndType(userId);
        return instance(ResultCode.SUCCESS, customActivityStatistics);
    }

    /**
     * 活动记录_详情
     */
    @GetMapping("activity/info")
    @ApiOperation(value = "用户活动/志愿者记录_详情", notes = "用户活动/志愿者记录_详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "activityId", value = "活动id", paramType = "query", dataType = "String")
    })
    public ApiResult<List<UserActivityLog>> getActivityStatistics(@RequestParam String userId, @RequestParam String activityId) {
        List<UserActivityLog> userActivityLogList = userActivityLogService.findByUserIdAndActivityId(userId, activityId);
        return instance(ResultCode.SUCCESS, userActivityLogList);
    }

    /**
     * 现场记录_列表
     */
    @GetMapping("location/list")
    @ApiOperation(value = "用户现场记录_列表", notes = "用户现场记录_列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页面尺寸", paramType = "query", dataType = "int")
    })
    public ApiResult<PageInfo<UserLocationListResponse>> getLocationList(@RequestParam String userId, @RequestParam(required = false, defaultValue = "1") int pageNum, @RequestParam(required = false, defaultValue = "5") int pageSize) {
        PageInfo<UserLocationListResponse> userLocationListResponsePageInfo = userLocationService.findLocationList(userId, pageNum, pageSize);
        return instance(ResultCode.SUCCESS, userLocationListResponsePageInfo);
    }

    /**
     * 现场记录_统计（占比图+热力图）
     */
    @GetMapping("location/statistics")
    @ApiOperation(value = "用户现场记录_统计", notes = "用户现场记录_统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String")
    })
    public ApiResult<CustomLocationStatistics> getLocationStatistics(@RequestParam String userId) {
        CustomLocationStatistics locationStatistics = userLocationService.findByUserId(userId);
        return instance(ResultCode.SUCCESS, locationStatistics);
    }

    /**
     * 聚合类型的用户分析
     */
    @GetMapping("analysis")
    @ApiOperation(value = "聚合类型的用户分析", notes = "聚合类型的用户分析")
    @ApiImplicitParam(name = "type", value = "聚合类型：活动/培训/场地", paramType = "query", dataType = "String", required = true)
    public ApiResult<Map<String, List<CustomListUser>>> getUserAnalysis(@RequestParam String type) {
        Map<String, List<CustomListUser>> userAnalysis = userService.getUserAnalysis(type);
        return instance(ResultCode.SUCCESS, userAnalysis);
    }

    /**
     * 积分记录_列表（无用）
     */
    @GetMapping("point/list")
    @ApiOperation(value = "用户积分记录_列表", notes = "用户积分记录_列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页面尺寸", paramType = "query", dataType = "int")
    })
    public ApiResult<PageInfo<UserPointListResponse>> getPointList(@RequestParam String userId, @RequestParam(required = false, defaultValue = "1") int pageNum, @RequestParam(required = false, defaultValue = "5") int pageSize) {
        PageInfo<UserPointListResponse> userPointListResponsePageInfo = userPointService.findPointList(userId, pageNum, pageSize);
        return instance(ResultCode.SUCCESS, userPointListResponsePageInfo);
    }

    /**
     * 积分记录_统计（无用）
     */
    @GetMapping("point/statistics")
    @ApiOperation(value = "用户积分记录_统计", notes = "用户积分记录_统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", paramType = "query", dataType = "String")
    })
    public ApiResult<CustomPointStatistics> getPointStatistics(@RequestParam String userId) {
        CustomPointStatistics customPointStatistics = userPointService.findPointStatisticsByUserId(userId);
        return instance(ResultCode.SUCCESS, customPointStatistics);
    }

}


